//
//  ProtocalTest.swift
//  swift-learningTests
//
//  Created by aron on 2018/5/17.
//  Copyright © 2018年 aron. All rights reserved.
//

import XCTest

class ProtocolTest: XCTestCase {
    
    override func setUp() {
        super.setUp()
        print("=========================")
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
    }
    
    func testPerformanceExample() {
        // This is an example of a performance test case.
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }
    
    func testProtocolProp() {
        let studdet = ClassA()
        studdet.stname = "Swift"
        studdet.marks = 98
        print(studdet.markssecured())
        
        print(studdet.marks)
        print(studdet.result)
        print(studdet.present)
        print(studdet.subject)
        print(studdet.stname)
    }
    
    func testProtocolForClassOnly() {
        let myCls = MyClass()
        myCls.sayHello(name: "zyt")
    }
}

protocol protocolA {
    var marks: Int { get set }
    var result: Bool { get }
    
    func attendance() -> String
    func markssecured() -> String
}

protocol protocolB: protocolA {
    var present: Bool { get set }
    var subject: String { get set }
    var stname: String { get set }
}

class ClassA: protocolB {
    var marks = 96
    let result = true
    var present = false
    var subject = "Swift 协议"
    var stname = "Protocols"
    
    func attendance() -> String {
        return "The \(stname) has secured 99% attendance"
    }
    
    func markssecured() -> String {
        return "\(stname) has scored \(marks)"
    }
}


// MARK:- 类专属协议
protocol SomeClassOnlyProtocol: class {
    func sayHello(name: String)
}

// Non-class type 'MyStruct' cannot conform to class protocol 'SomeClassOnlyProtocol'
//struct MyStruct: SomeClassOnlyProtocol {
//    func sayHello(name: String) {
//        print("MyStruct sayHello \(name)")
//    }
//}

class MyClass : SomeClassOnlyProtocol {
    func sayHello(name: String) {
        print("MyClass sayHello \(name)")
    }
}
